﻿// ===============================================================================
// XCI.Parent 西安交通信息WinForm开发框架 2019 版权所有
// ===============================================================================

// ===============================================================================
// Copyright(c) 2007-2020 西安交通信息投资营运有限公司 版权所有
// 作者:马星俊
// ===============================================================================

using System;
using XCI.Sys.Model;
using XCI.Sys.Service;
using XCI.Windows;

namespace XCI.Sys.Forms
{
    public partial class FrmRoleEdit : BaseForm
    {
        public FrmRoleEdit(EditFormArgs args)
        {
            InitializeComponent();
            layoutControl.Args = args;
        }

        private async void FrmRoleEdit_Load(object sender, EventArgs e)
        {
            await layoutControl.BindingModelAsync();
        }

        private async void btnSave_Click(object sender, EventArgs e)
        {
            await layoutControl.SaveModelAsync();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            DialogOk();
        }

        private void LayoutControl_BindingForm(object sender, EditFormPanelBindingEventArgs e)
        {
            e.Task = async () =>
            {
                bindingSource.DataSource = await SysRoleService.Instance.GetOrCreateAsync(e.Args);
            };
        }

        private void LayoutControl_SaveForm(object sender, EditFormPanelSaveEventArgs e)
        {
            e.Task = () => SysRoleService.Instance.SaveAsync(e.Args.Created, (SysRole)e.Model);
        }

        private async void LayoutControl_ResetForm(object sender, EditFormPanelResetEventArgs e)
        {

            bindingSource.DataSource = await SysRoleService.Instance.NewAsync();
            await layoutControl.BindingModelAsync();
        }
    }
}